package com.itcast.donkey.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itcast.donkey.R;
import com.itcast.donkey.modles.DetailedJourneyModles;

/**
 * Created by lanouhn on 16/9/3.
 */
public class PopMenuDetailJourneyAdapter extends BaseExpandableListAdapter {

    private Context context;
    private DetailedJourneyModles modles;


    public PopMenuDetailJourneyAdapter(Context context, DetailedJourneyModles modles) {
        this.context = context;
        this.modles = modles;
    }

    @Override
    public int getGroupCount() {
        return modles.getPlan_days().size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return modles.getPlan_days().get(groupPosition).getPlan_nodes().size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return modles.getPlan_days().get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return modles.getPlan_days().get(groupPosition).getPlan_nodes().get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        LinearLayout linearLayout = new LinearLayout(context);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        TextView textView = new TextView(context);

        textView.setText("DAY" + (groupPosition + 1) + "  " + modles.getPlan_days().get(groupPosition).getPlan_nodes().get(0).getDestination().getName_zh_cn());
        textView.setTextColor(context.getResources().getColor(R.color.travel_content));
        textView.setTextSize(18);
        textView.setPadding(20, 13, 0, 0);
        linearLayout.addView(textView);
        return linearLayout;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

        LinearLayout linearLayout = new LinearLayout(context);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        TextView text = new TextView(context);
        text.setText(modles.getPlan_days().get(groupPosition).getPlan_nodes().get(childPosition).getEntry_name());
        text.setTextColor(context.getResources().getColor(R.color.travel_content));
        text.setPadding(30, 8, 0, 0);
        linearLayout.addView(text);

        return linearLayout;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}
